/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonClasses.Messages;

import commonClasses.*;
import commonClasses.commonInterfaces.MsgIntf;
import commonClasses.commonInterfaces.ProtocolIntf;

/**
 *
 * @author Pozytywny!
 */
public class NakMsg extends Msg implements MsgIntf {

    private String _reason;

    public NakMsg(ProtocolIntf protocol, String reason) {
        super(protocol, MagicNumbers.NAK_MSG_NR);
        _reason = reason;
    }

    public NakMsg(ProtocolIntf protocol) {
        super(protocol, MagicNumbers.NAK_MSG_NR);
    }

    public String getReason() {
        return _reason;
    }

    public void receive() throws Exception {
        int length = longToInt(receiveUint());
        Utils.clientReceived(length);

        _reason = String.valueOf(receiveCharArr(length));
        Utils.clientReceived(_reason);

    }

    public void send() throws Exception {
        int mesgId[] = this.idToIntArr();
        sendIntArr(mesgId);

        int length[] = longToArr(_reason.length());
        Utils.write("length" + Msg.intArrToLong(length));
        sendIntArr(length);

        char reason[] = stringToCharArr(_reason);
        sendCharArr(reason, _reason.length());
    }
}
